
import com.mavenTest.dao.ProductDao;
import com.mavenTest.entity.Product;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Test;

import org.apache.ibatis.io.*;

import java.io.IOException;
import java.io.InputStream;

/**
 * @author XIAOLIANG
 * @ClassName test.java
 * @Description TODO
 * @createTime 2021年03月05日 15:40:00
 */
public class test {

	@Test
	public void mybatisTest(){
		InputStream stream = null;
		try {
			stream = Resources.getResourceAsStream("mybatis-config.xml");
		} catch (IOException e) {
			e.printStackTrace();
		}
		SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(stream);
		SqlSession sqlSession = sqlSessionFactory.openSession();
		ProductDao mapper = sqlSession.getMapper(ProductDao.class);
		Product product = mapper.selectOnrById(20);
		sqlSession.close();
		System.out.println(product);
	}

}
